//
//  JGRealOrderListApi.m
//  JGRider
//
//  Created by 单启志 on 2018/3/9.
//  Copyright © 2018年 ffq. All rights reserved.
//

#import "JGRealOrderListApi.h"
#import "JGRealTimeOrderModel.h"
@interface JGRealOrderListApi()
@property(nonatomic,assign)NSInteger page;

@end

@implementation JGRealOrderListApi

-(NSString *)requestUrl{
    return @"api/order/order.do?action=getRidOrderList";
}

-(id)jsonValidator{

   return  @{
      @"code":[NSString class],
      @"data":@{
              @"state":[NSString class],
              @"msg":[NSString class],
              @"obj":@{
                      @"pageCount":[NSNumber class],
                      @"pageNo":[NSNumber class],
                      @"pageSize":[NSNumber class],
                      @"orderList":[NSArray class]
                      }
              },
      @"message":[NSString class],
      };
}



#pragma mark - 根据具体情况暴露出来的方法
-(void)getRealOrderListMid:(NSString *)mid isMore:(BOOL)isMore successBlock:(void(^)(id result))invokeSuccessBlock faileBlock:(void(^)(id error))invokeFaileBlock{

    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"mid"] = mid;
    params[@"pageSize"] = @"10";
    NSInteger page = isMore ? (self.page + 1) : 1;
    params[@"pageNo"] = @(page);

    [[JGRequestHelper share]requestWithParams:params requestApi:[self class] successBlock:^(id result) {
        if (!isMore) {
            [self.datas removeAllObjects];
        }
        NSArray *arr=result[@"data"][@"obj"][@"orderList"];
        if ([arr isKindOfClass:[NSArray class]]) {
            NSArray*models=[JGRealTimeOrderModel mj_objectArrayWithKeyValuesArray:arr];
            [self.datas addObjectsFromArray:models];
        }
        //记录页码
        self.page = page;

        invokeSuccessBlock(result);
    } faileBlock:^(id error) {
        invokeFaileBlock(error);
    }];
}

-(NSMutableArray<JGRealTimeOrderModel*> *)datas{
    if (!_datas) {
        _datas=[NSMutableArray array];
    }
    return _datas;
}


@end
